﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using BodaNetCommunications.Utilities.ComTypes;

namespace BodaNetCommunications.Utilities.DataLibs
{
    public class UIntLib
    {
        public static uint GetUIntFromByteArray(byte[] source, int start = 0, EndianType type = EndianType.ABCD)
        {
            return BitConverter.ToUInt32(ByteArrayLib.Get4ByteArray(source, start, type), 0);
        }

        public static uint[] GetUIntArrayFromByteArray(byte[] source, EndianType type = EndianType.ABCD)
        {
            uint[] array = new uint[source.Length / 4];
            for (int i = 0; i < source.Length / 4; i++)
            {
                array[i] = GetUIntFromByteArray(source, 4 * i, type);
            }

            return array;
        }

        public static uint[] GetUIntArrayFromString(string val)
        {
            List<uint> list = new List<uint>();
            if (val.Contains(' '))
            {
                string[] array = Regex.Split(val, "\\s+", RegexOptions.IgnoreCase);
                string[] array2 = array;
                foreach (string value in array2)
                {
                    list.Add(Convert.ToUInt32(value));
                }
            }
            else
            {
                list.Add(Convert.ToUInt32(val));
            }

            return list.ToArray();
        }
    }
}